/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ensisa.hassenforder.game.client;

import java.util.Collection;
import java.util.Iterator;

import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.SwingUtilities;

import fr.ensisa.hassenforder.game.model.Player;
import fr.ensisa.hassenforder.game.model.Product;

/**
 *
 * @author hassenforder
 */
public class GUI extends javax.swing.JFrame {

	private Application app;
	private Group groups[];

	private class Group {
		public javax.swing.JLabel jCategory;
		public javax.swing.JLabel jName;
		public javax.swing.JButton jImage;
		public javax.swing.JLabel jTime;
		public javax.swing.JLabel jStackable;
		public javax.swing.JLabel jCount;
		
		public Group(JLabel jCategory, JLabel jName, JButton jImage, JLabel jTime, JLabel jStackable, JLabel jCount) {
			super();
			this.jCategory = jCategory;
			this.jName = jName;
			this.jImage = jImage;
			this.jTime = jTime;
			this.jStackable = jStackable;
			this.jCount = jCount;
		}

	}

	/**
     * Creates new form GUI
     */
    public GUI(Application app) {
    	this.app = app;
    	initComponents();
    	registerComponents ();
    }

    private void registerComponents() {
    	groups = new Group [6];
    	groups[0] = new Group (jCategoryItem1, jNameItem1, jImageItem1, jTimeItem1, jStackableItem1, jCountItem1);
    	groups[1] = new Group (jCategoryItem2, jNameItem2, jImageItem2, jTimeItem2, jStackableItem2, jCountItem2);
    	groups[2] = new Group (jCategoryItem3, jNameItem3, jImageItem3, jTimeItem3, jStackableItem3, jCountItem3);
    	groups[3] = new Group (jCategoryShop1, jNameShop1, jImageShop1, jTimeShop1, jStackableShop1, jCountShop1);
    	groups[4] = new Group (jCategoryShop2, jNameShop2, jImageShop2, jTimeShop2, jStackableShop2, jCountShop2);
    	groups[5] = new Group (jCategoryShop3, jNameShop3, jImageShop3, jTimeShop3, jStackableShop3, jCountShop3);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPlayer = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPassword = new javax.swing.JTextField();
        jConnect = new javax.swing.JButton();
        jDisconnect = new javax.swing.JButton();
        jCash = new javax.swing.JLabel();
        jImage = new javax.swing.JButton();
        jAddCash = new javax.swing.JButton();
        jSubCash = new javax.swing.JButton();
        jClear = new javax.swing.JButton();
        jConsume = new javax.swing.JButton();
        jPanelItems = new javax.swing.JPanel();
        jStatistics = new javax.swing.JButton();
        jProducts = new javax.swing.JButton();
        jPanelItem1 = new javax.swing.JPanel();
        jCategoryItem1 = new javax.swing.JLabel();
        jNameItem1 = new javax.swing.JLabel();
        jTimeItem1 = new javax.swing.JLabel();
        jStackableItem1 = new javax.swing.JLabel();
        jCountItem1 = new javax.swing.JLabel();
        jImageItem1 = new javax.swing.JButton();
        jPanelItem2 = new javax.swing.JPanel();
        jCategoryItem2 = new javax.swing.JLabel();
        jNameItem2 = new javax.swing.JLabel();
        jTimeItem2 = new javax.swing.JLabel();
        jStackableItem2 = new javax.swing.JLabel();
        jCountItem2 = new javax.swing.JLabel();
        jImageItem2 = new javax.swing.JButton();
        jPanelItem3 = new javax.swing.JPanel();
        jCategoryItem3 = new javax.swing.JLabel();
        jNameItem3 = new javax.swing.JLabel();
        jTimeItem3 = new javax.swing.JLabel();
        jStackableItem3 = new javax.swing.JLabel();
        jCountItem3 = new javax.swing.JLabel();
        jImageItem3 = new javax.swing.JButton();
        jPanelShop = new javax.swing.JPanel();
        jShop = new javax.swing.JButton();
        jRefresh = new javax.swing.JButton();
        jPanelShop1 = new javax.swing.JPanel();
        jCategoryShop1 = new javax.swing.JLabel();
        jNameShop1 = new javax.swing.JLabel();
        jTimeShop1 = new javax.swing.JLabel();
        jStackableShop1 = new javax.swing.JLabel();
        jCountShop1 = new javax.swing.JLabel();
        jImageShop1 = new javax.swing.JButton();
        jPanelShop2 = new javax.swing.JPanel();
        jCategoryShop2 = new javax.swing.JLabel();
        jNameShop2 = new javax.swing.JLabel();
        jTimeShop2 = new javax.swing.JLabel();
        jStackableShop2 = new javax.swing.JLabel();
        jCountShop2 = new javax.swing.JLabel();
        jImageShop2 = new javax.swing.JButton();
        jPanelShop3 = new javax.swing.JPanel();
        jCategoryShop3 = new javax.swing.JLabel();
        jNameShop3 = new javax.swing.JLabel();
        jTimeShop3 = new javax.swing.JLabel();
        jStackableShop3 = new javax.swing.JLabel();
        jCountShop3 = new javax.swing.JLabel();
        jImageShop3 = new javax.swing.JButton();
        jStatus = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Name");

        jLabel2.setText("Password");

        jConnect.setText("connect");
        jConnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jConnectMouseClicked(evt);
            }
        });

        jDisconnect.setText("disconnect");
        jDisconnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jDisconnectMouseClicked(evt);
            }
        });

        jCash.setText("Cash");

        jImage.setText("image");
        jImage.setBorderPainted(false);
        
        jAddCash.setText("add");
        jAddCash.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAddCashMouseClicked(evt);
            }
        });

        jSubCash.setText("sub");
        jSubCash.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jSubCashMouseClicked(evt);
            }
        });

        jClear.setText("clear");
        jClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jClearMouseClicked(evt);
            }
        });

        jConsume.setText("consume");
        jConsume.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jConsumeMouseClicked(evt);
            }
        });

        jPanelItems.setBorder(javax.swing.BorderFactory.createTitledBorder("Items"));

        jStatistics.setText("statistics");
        jStatistics.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jStatisticsMouseClicked(evt);
            }
        });

        jProducts.setText("products");
        jProducts.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jProductsMouseClicked(evt);
            }
        });

        jPanelItem1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jCategoryItem1.setText("category");

        jNameItem1.setText("name");

        jTimeItem1.setText("time");

        jStackableItem1.setText("stackable");

        jCountItem1.setText("count");

        jImageItem1.setText("image");
        jImageItem1.setBorderPainted(false);
        jImageItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jImageItem1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelItem1Layout = new javax.swing.GroupLayout(jPanelItem1);
        jPanelItem1.setLayout(jPanelItem1Layout);
        jPanelItem1Layout.setHorizontalGroup(
            jPanelItem1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelItem1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelItem1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jCategoryItem1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jNameItem1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTimeItem1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jStackableItem1, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(jCountItem1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jImageItem1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelItem1Layout.setVerticalGroup(
            jPanelItem1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelItem1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelItem1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jImageItem1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanelItem1Layout.createSequentialGroup()
                        .addComponent(jCategoryItem1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jNameItem1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTimeItem1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jStackableItem1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCountItem1)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanelItem2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jCategoryItem2.setText("category");

        jNameItem2.setText("name");

        jTimeItem2.setText("time");

        jStackableItem2.setText("stackable");

        jCountItem2.setText("count");

        jImageItem2.setText("image");
        jImageItem2.setBorderPainted(false);
        jImageItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jImageItem2MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelItem2Layout = new javax.swing.GroupLayout(jPanelItem2);
        jPanelItem2.setLayout(jPanelItem2Layout);
        jPanelItem2Layout.setHorizontalGroup(
            jPanelItem2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelItem2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelItem2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jCategoryItem2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jNameItem2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTimeItem2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jStackableItem2, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(jCountItem2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jImageItem2, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelItem2Layout.setVerticalGroup(
            jPanelItem2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelItem2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelItem2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jImageItem2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanelItem2Layout.createSequentialGroup()
                        .addComponent(jCategoryItem2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jNameItem2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTimeItem2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jStackableItem2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCountItem2)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanelItem3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jCategoryItem3.setText("category");

        jNameItem3.setText("name");

        jTimeItem3.setText("time");

        jStackableItem3.setText("stackable");

        jCountItem3.setText("count");

        jImageItem3.setText("image");
        jImageItem3.setBorderPainted(false);
        jImageItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jImageItem3MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelItem3Layout = new javax.swing.GroupLayout(jPanelItem3);
        jPanelItem3.setLayout(jPanelItem3Layout);
        jPanelItem3Layout.setHorizontalGroup(
            jPanelItem3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelItem3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelItem3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jCategoryItem3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jNameItem3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTimeItem3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jStackableItem3, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(jCountItem3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jImageItem3, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelItem3Layout.setVerticalGroup(
            jPanelItem3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelItem3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelItem3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jImageItem3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanelItem3Layout.createSequentialGroup()
                        .addComponent(jCategoryItem3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jNameItem3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTimeItem3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jStackableItem3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCountItem3)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanelItemsLayout = new javax.swing.GroupLayout(jPanelItems);
        jPanelItems.setLayout(jPanelItemsLayout);
        jPanelItemsLayout.setHorizontalGroup(
            jPanelItemsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelItem2, javax.swing.GroupLayout.PREFERRED_SIZE, 210, Short.MAX_VALUE)
            .addComponent(jPanelItem3, javax.swing.GroupLayout.PREFERRED_SIZE, 210, Short.MAX_VALUE)
            .addComponent(jPanelItem1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, Short.MAX_VALUE)
            .addGroup(jPanelItemsLayout.createSequentialGroup()
                .addComponent(jStatistics)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jProducts)
                .addGap(0, 54, Short.MAX_VALUE))
        );
        jPanelItemsLayout.setVerticalGroup(
            jPanelItemsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelItemsLayout.createSequentialGroup()
                .addGroup(jPanelItemsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jStatistics)
                    .addComponent(jProducts))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanelItem1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelItem2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelItem3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanelShop.setBorder(javax.swing.BorderFactory.createTitledBorder("Shop"));

        jShop.setText("shop");
        jShop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jShopMouseClicked(evt);
            }
        });

        jRefresh.setText("refresh");
        jRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRefreshMouseClicked(evt);
            }
        });

        jPanelShop1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jCategoryShop1.setText("category");

        jNameShop1.setText("name");

        jTimeShop1.setText("time");

        jStackableShop1.setText("stackable");

        jCountShop1.setText("count");

        jImageShop1.setText("image");
        jImageShop1.setBorderPainted(false);
        jImageShop1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jImageShop1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelShop1Layout = new javax.swing.GroupLayout(jPanelShop1);
        jPanelShop1.setLayout(jPanelShop1Layout);
        jPanelShop1Layout.setHorizontalGroup(
            jPanelShop1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelShop1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelShop1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jCategoryShop1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jNameShop1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTimeShop1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jStackableShop1, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(jCountShop1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jImageShop1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelShop1Layout.setVerticalGroup(
            jPanelShop1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelShop1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelShop1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jImageShop1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanelShop1Layout.createSequentialGroup()
                        .addComponent(jCategoryShop1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jNameShop1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTimeShop1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jStackableShop1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCountShop1)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanelShop2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jCategoryShop2.setText("category");

        jNameShop2.setText("name");

        jTimeShop2.setText("time");

        jStackableShop2.setText("stackable");

        jCountShop2.setText("count");

        jImageShop2.setText("image");
        jImageShop2.setBorderPainted(false);
        jImageShop2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jImageShop2MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelShop2Layout = new javax.swing.GroupLayout(jPanelShop2);
        jPanelShop2.setLayout(jPanelShop2Layout);
        jPanelShop2Layout.setHorizontalGroup(
            jPanelShop2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelShop2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelShop2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jCategoryShop2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jNameShop2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTimeShop2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jStackableShop2, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(jCountShop2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jImageShop2, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelShop2Layout.setVerticalGroup(
            jPanelShop2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelShop2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelShop2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jImageShop2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanelShop2Layout.createSequentialGroup()
                        .addComponent(jCategoryShop2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jNameShop2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTimeShop2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jStackableShop2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCountShop2)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanelShop3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jCategoryShop3.setText("category");

        jNameShop3.setText("name");

        jTimeShop3.setText("time");

        jStackableShop3.setText("stackable");

        jCountShop3.setText("count");

        jImageShop3.setText("image");
        jImageShop3.setBorderPainted(false);
        jImageShop3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jImageShop3MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelShop3Layout = new javax.swing.GroupLayout(jPanelShop3);
        jPanelShop3.setLayout(jPanelShop3Layout);
        jPanelShop3Layout.setHorizontalGroup(
            jPanelShop3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelShop3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelShop3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jCategoryShop3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jNameShop3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTimeShop3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jStackableShop3, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(jCountShop3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jImageShop3, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelShop3Layout.setVerticalGroup(
            jPanelShop3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelShop3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelShop3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jImageShop3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanelShop3Layout.createSequentialGroup()
                        .addComponent(jCategoryShop3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jNameShop3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTimeShop3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jStackableShop3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCountShop3)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanelShopLayout = new javax.swing.GroupLayout(jPanelShop);
        jPanelShop.setLayout(jPanelShopLayout);
        jPanelShopLayout.setHorizontalGroup(
            jPanelShopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelShopLayout.createSequentialGroup()
                .addGroup(jPanelShopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanelShop1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelShop2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanelShopLayout.createSequentialGroup()
                        .addComponent(jShop)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRefresh))
                    .addComponent(jPanelShop3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelShopLayout.setVerticalGroup(
            jPanelShopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelShopLayout.createSequentialGroup()
                .addGroup(jPanelShopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jShop)
                    .addComponent(jRefresh))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelShop1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelShop2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanelShop3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jStatus.setText("Status");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelItems, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jStatus))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelShop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jConnect)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jDisconnect))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel2)
                                        .addComponent(jLabel1))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jPlayer)
                                        .addComponent(jPassword))))
                            .addComponent(jCash))
                        .addGap(18, 18, 18)
                        .addComponent(jImage, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jAddCash)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jSubCash))
                            .addComponent(jClear, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jConsume, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jPlayer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jSubCash)
                            .addComponent(jAddCash))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2)
                                .addComponent(jPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jClear))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jConnect)
                            .addComponent(jDisconnect)
                            .addComponent(jConsume))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCash))
                    .addComponent(jImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanelShop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanelItems, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jStatus))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 11, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    private void jConnectMouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jConnectMouseClicked
    	String n = jPlayer.getText();
    	String p = jPassword.getText();
    	boolean r = app.doConnect(n, p);
    	if (r) {
    		jStatus.setText("You are now connected");
    	} else {
    		jStatus.setText("Connection failed");
    	}
    }//GEN-LAST:event_jConnectMouseClicked

    private void jDisconnectMouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jDisconnectMouseClicked
    	boolean r = app.doDisconnect();
    	if (r) {
    		jStatus.setText("You are now disconnected");
    	} else {
    		jStatus.setText("Disconnection failed");
    	}
    }//GEN-LAST:event_jDisconnectMouseClicked

    private void jImageItem1MouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jImageItem1MouseClicked
    	String productName = jNameItem1.getText();
    	boolean r = app.doSellProduct(productName);
    	if (r) {
    		jStatus.setText("You successfully sell "+productName);
    	} else {
    		jStatus.setText("You failed sell "+productName);
    	}
    }//GEN-LAST:event_jImageItem1MouseClicked

    private void jImageItem2MouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jImageItem2MouseClicked
    	String productName = jNameItem2.getText();
    	boolean r = app.doSellProduct(productName);
    	if (r) {
    		jStatus.setText("You successfully sell "+productName);
    	} else {
    		jStatus.setText("You failed sell "+productName);
    	}
    }//GEN-LAST:event_jImageItem2MouseClicked

    private void jImageItem3MouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jImageItem3MouseClicked
    	String productName = jNameItem3.getText();
    	boolean r = app.doSellProduct(productName);
    	if (r) {
    		jStatus.setText("You successfully sell "+productName);
    	} else {
    		jStatus.setText("You failed sell "+productName);
    	}
    }//GEN-LAST:event_jImageItem3MouseClicked

    private void jImageShop1MouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jImageShop1MouseClicked
    	String productName = jNameShop1.getText();
    	boolean r = app.doBuyProduct(productName);
    	if (r) {
    		jStatus.setText("You successfully buy "+productName);
    	} else {
    		jStatus.setText("You failed buy "+productName);
    	}
    }//GEN-LAST:event_jImageShop1MouseClicked

    private void jImageShop2MouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jImageShop2MouseClicked
    	String productName = jNameShop2.getText();
    	boolean r = app.doBuyProduct(productName);
    	if (r) {
    		jStatus.setText("You successfully buy "+productName);
    	} else {
    		jStatus.setText("You failed buy "+productName);
    	}
    }//GEN-LAST:event_jImageShop2MouseClicked

    private void jImageShop3MouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jImageShop3MouseClicked
    	String productName = jNameShop3.getText();
    	boolean r = app.doBuyProduct(productName);
    	if (r) {
    		jStatus.setText("You successfully buy "+productName);
    	} else {
    		jStatus.setText("You failed buy "+productName);
    	}
    }//GEN-LAST:event_jImageShop3MouseClicked

    private void jStatisticsMouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jStatisticsMouseClicked
    	Player player = app.doGetStatistics();
    	if (player != null) {
    		jCash.setText("You have "+Integer.toString(player.getCash())+" coins");
    		SwingUtilities.invokeLater(new ImageLoader (app, player.getImage(), jImage));
    		jStatus.setText("You obtain your statistics");
    	} else {
    		jStatus.setText("You failed obtain your statistics");
    	}
    }//GEN-LAST:event_jStatisticsMouseClicked

    private void clearItem (Group g) {
		g.jCategory.setText("---");
		g.jName.setText("no name");
		SwingUtilities.invokeLater(new ImageLoader (app, null, g.jImage));
		g.jTime.setText("");
		g.jStackable.setText("");
		g.jCount.setText("");
    }
    
    private void updateItem (Group g, Product product) {
		g.jCategory.setText(product.getCategory().toString().toLowerCase());
		g.jName.setText(product.getName());
		SwingUtilities.invokeLater(new ImageLoader (app, product.getImage(), g.jImage));
    	if (product.getRemainingTime() == Long.MAX_VALUE) {
    		if (product.getDuration() == 0) {
        		g.jTime.setText("eternal life");
    		} else {
    			g.jTime.setText("live "+Integer.toString(product.getDuration())+"s");
    		}
    	} else {
    		g.jTime.setText("remains "+Long.toString(product.getRemainingTime()/1000)+"s");
    	}
		if (product.isStackable()) g.jStackable.setText("stackable");
		else g.jStackable.setText("one only");
		switch (product.getCount()) {
		case 0 :  g.jCount.setText(""); break;
		case 1 :  g.jCount.setText(Integer.toString(product.getCount())+" piece"); break;
		default:  g.jCount.setText(Integer.toString(product.getCount())+" pieces"); break;
		}
    }

    private void jProductsMouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jProductsMouseClicked
    	Collection<Product> products = app.doGetProducts();
    	if (products != null) {
    		Iterator<Product> ip = products.iterator();
    		for (int i=0; i<3;++i) {
    			Product p = null;
    			if (ip.hasNext()) {
    				p = ip.next();
        			updateItem (groups[i], p);
    			} else {
        			clearItem (groups[i]);
    			}
    		}
    		jStatus.setText("You obtain your products");
    	} else {
    		jStatus.setText("You failed obtain your products");
    	}
    }//GEN-LAST:event_jProductsMouseClicked

    private void jShopMouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jShopMouseClicked
    	Collection<Product> products = app.doGetShop();
    	if (products != null) {
    		Iterator<Product> ip = products.iterator();
    		for (int i=3; i<6;++i) {
    			Product p = null;
    			if (ip.hasNext()) {
    				p = ip.next();
        			updateItem (groups[i], p);
    			} else {
        			clearItem (groups[i]);
    			}
    		}
    		jStatus.setText("You obtain the shop");
    	} else {
    		jStatus.setText("You failed obtain the shop");
    	}
    }//GEN-LAST:event_jShopMouseClicked

    private void jRefreshMouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRefreshMouseClicked
    	boolean r = app.doRefreshShop();
    	if (r) {
    		jStatus.setText("You successfully refresh the shop");
    	} else {
    		jStatus.setText("You failed refresh the shop");
    	}
    }//GEN-LAST:event_jRefreshMouseClicked

    private void jAddCashMouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAddCashMouseClicked
    	boolean r = app.doAddCash(500);
    	if (r) {
    		jStatus.setText("You successfully receive coins");
    	} else {
    		jStatus.setText("You failed to receive coins");
    	}
    }//GEN-LAST:event_jAddCashMouseClicked

    private void jSubCashMouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jSubCashMouseClicked
    	boolean r = app.doSubCash(200);
    	if (r) {
    		jStatus.setText("You successfully spend coins");
    	} else {
    		jStatus.setText("You failed to spend coins");
    	}
    }//GEN-LAST:event_jSubCashMouseClicked

    private void jClearMouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jClearMouseClicked
    	boolean r = app.doClearProducts();
    	if (r) {
    		jStatus.setText("You successfully remove all products");
    	} else {
    		jStatus.setText("You failed to remove all products");
    	}
    }//GEN-LAST:event_jClearMouseClicked

    private void jConsumeMouseClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jConsumeMouseClicked
    	boolean r = app.doConsumeProducts();
    	if (r) {
    		jStatus.setText("You successfully consume products");
    	} else {
    		jStatus.setText("You failed to consume products");
    	}
    }//GEN-LAST:event_jConsumeMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUI(null).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jAddCash;
    private javax.swing.JLabel jCash;
    private javax.swing.JLabel jCategoryItem1;
    private javax.swing.JLabel jCategoryItem2;
    private javax.swing.JLabel jCategoryItem3;
    private javax.swing.JLabel jCategoryShop1;
    private javax.swing.JLabel jCategoryShop2;
    private javax.swing.JLabel jCategoryShop3;
    private javax.swing.JButton jClear;
    private javax.swing.JButton jConnect;
    private javax.swing.JButton jConsume;
    private javax.swing.JLabel jCountItem1;
    private javax.swing.JLabel jCountItem2;
    private javax.swing.JLabel jCountItem3;
    private javax.swing.JLabel jCountShop1;
    private javax.swing.JLabel jCountShop2;
    private javax.swing.JLabel jCountShop3;
    private javax.swing.JButton jDisconnect;
    private javax.swing.JButton jImage;
    private javax.swing.JButton jImageItem1;
    private javax.swing.JButton jImageItem2;
    private javax.swing.JButton jImageItem3;
    private javax.swing.JButton jImageShop1;
    private javax.swing.JButton jImageShop2;
    private javax.swing.JButton jImageShop3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jNameItem1;
    private javax.swing.JLabel jNameItem2;
    private javax.swing.JLabel jNameItem3;
    private javax.swing.JLabel jNameShop1;
    private javax.swing.JLabel jNameShop2;
    private javax.swing.JLabel jNameShop3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelItem1;
    private javax.swing.JPanel jPanelItem2;
    private javax.swing.JPanel jPanelItem3;
    private javax.swing.JPanel jPanelItems;
    private javax.swing.JPanel jPanelShop;
    private javax.swing.JPanel jPanelShop1;
    private javax.swing.JPanel jPanelShop2;
    private javax.swing.JPanel jPanelShop3;
    private javax.swing.JTextField jPassword;
    private javax.swing.JTextField jPlayer;
    private javax.swing.JButton jProducts;
    private javax.swing.JButton jRefresh;
    private javax.swing.JButton jShop;
    private javax.swing.JLabel jStackableItem1;
    private javax.swing.JLabel jStackableItem2;
    private javax.swing.JLabel jStackableItem3;
    private javax.swing.JLabel jStackableShop1;
    private javax.swing.JLabel jStackableShop2;
    private javax.swing.JLabel jStackableShop3;
    private javax.swing.JButton jStatistics;
    private javax.swing.JLabel jStatus;
    private javax.swing.JButton jSubCash;
    private javax.swing.JLabel jTimeItem1;
    private javax.swing.JLabel jTimeItem2;
    private javax.swing.JLabel jTimeItem3;
    private javax.swing.JLabel jTimeShop1;
    private javax.swing.JLabel jTimeShop2;
    private javax.swing.JLabel jTimeShop3;
    // End of variables declaration//GEN-END:variables
}
